//
//  CurrnecyExchaqngeLiquidityGmoTable.m
//  DataCollector
//
//  Created by jiro on 12/07/10.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "CurrencyExchangeLiquidityGmo.h"

#import "../../DbUtility.h"
#import "../../DbConstants.h"

@implementation CurrencyExchangeLiquidityGmo

@synthesize code;
@synthesize targetCurrencyCode;
@synthesize exchangeDate;
@synthesize liquidity;

+ (NSString*) tableName
{
	return kText_CurrencyExchangeLiquidiyGmoTable;
}

+ (CurrencyExchangeLiquidityGmo*)  currencyExchangeLiquidityGmoWithValues: (NSArray*) values
{
	CurrencyExchangeLiquidityGmo* ret	= [ [ CurrencyExchangeLiquidityGmo alloc ] init ];
	ret.code			= [ values objectAtIndex: 0 ];
	ret.targetCurrencyCode	= [ values objectAtIndex: 1 ];
	ret.exchangeDate		= [ NSDate dateWithString: 
									[ DbUtility convertIsoStdDateStringToCocoaDateString: [ values objectAtIndex: 2 ] ] ];
	ret.liquidity			= [ [ values objectAtIndex: 3 ] doubleValue ];
	return ret;
}

+ (NSString*) queryCreateTable
{
	NSString* s = [ NSString stringWithFormat: @"create table %@ ( %@ %@, %@ %@, %@ %@, %@ %@, %@( %@, %@, %@ ) );",
		[ CurrencyExchangeLiquidityGmo tableName ],
		kText_Code, kText_Text,
		kText_TargetCurrencyCode, kText_Text,
		kText_ExchangeDate, kText_TimestampWithTimeZone,
		kText_Liquidity, kText_Real,
		kText_PrimaryKey, kText_Code, kText_TargetCurrencyCode, kText_ExchangeDate 
	];
	return  s;
}

- (NSString*) queryInsert
{
	NSString* s = [ NSString stringWithFormat: @"insert into %@ values %@", 
		[ CurrencyExchangeLiquidityGmo tableName ], [ self queryInsertValue ] ];
	return s;
}

- (NSString*) queryInsertValue
{
	NSString* s = [ NSString stringWithFormat: @"( '%@', '%@', '%@', %f )",
		self.code, self.targetCurrencyCode, self.exchangeDate, self.liquidity
	];
	return s;
}

+ (NSString*) querySelectAll
{
	NSString* s = [ NSString stringWithFormat: @"select * from %@;", [ CurrencyExchangeLiquidityGmo tableName ] ];
	return s;
}

+ (NSString*) querySelectAllWithClauses: (NSArray*) clauses
{
	return [ DbTableEntry_ querySelectAllWithTableName: [ CurrencyExchangeLiquidityGmo tableName ] andClauses: clauses ];
}

+ (NSString*) querySelectFields: (NSArray*) fieldNodes andClauses: (NSArray*) clauses
{
	return [ DbTableEntry_ querySelectFields: fieldNodes tableName: [ CurrencyExchangeLiquidityGmo tableName ]andClauses: clauses ];
}

@end
